package com.titleevaluation.controller;

import com.titleevaluation.entity.WorkAchievements;
import com.titleevaluation.service.WorkAchievementsService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/applications/{applicationId}/work-achievements")
public class WorkAchievementsController {

    private final WorkAchievementsService workAchievementsService;

    public WorkAchievementsController(WorkAchievementsService workAchievementsService) {
        this.workAchievementsService = workAchievementsService;
    }

    @PostMapping
    public ResponseEntity<WorkAchievements> createWorkAchievements(@PathVariable Long applicationId, @RequestBody WorkAchievements workAchievements) {
        WorkAchievements createdWorkAchievements = workAchievementsService.createWorkAchievements(applicationId, workAchievements);
        return ResponseEntity.ok(createdWorkAchievements);
    }

    @GetMapping
    public ResponseEntity<List<WorkAchievements>> getWorkAchievementsByApplicationId(@PathVariable Long applicationId) {
        List<WorkAchievements> workAchievements = workAchievementsService.getWorkAchievementsByApplicationId(applicationId);
        return ResponseEntity.ok(workAchievements);
    }

    @GetMapping("/{id}")
    public ResponseEntity<WorkAchievements> getWorkAchievementsById(@PathVariable Long id) {
        return workAchievementsService.getWorkAchievementsById(id)
                .map(ResponseEntity::ok)
                .orElse(ResponseEntity.notFound().build());
    }

    @PutMapping("/{id}")
    public ResponseEntity<WorkAchievements> updateWorkAchievements(@PathVariable Long id, @RequestBody WorkAchievements workAchievements) {
        WorkAchievements updatedWorkAchievements = workAchievementsService.updateWorkAchievements(id, workAchievements);
        return ResponseEntity.ok(updatedWorkAchievements);
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Void> deleteWorkAchievements(@PathVariable Long id) {
        workAchievementsService.deleteWorkAchievements(id);
        return ResponseEntity.noContent().build();
    }
}

